package fy.hr.dao;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;

import com.soa.eis.adapter.framework.message.IMsgObject;
import com.soa.eis.adapter.framework.message.impl.GroupRecord;
import com.soa.eis.adapter.framework.message.impl.MsgObject;

import fy.hr.bean.PersonInfoByCodeBean;
import nc.ws.impl.MYWSServiceRequester;

public class HTTPPersonInfoDao {
	private String codes;
	private static Log log = LogFactory.getLog(HTTPPersonInfoDao.class);
	public JSONObject findPersonInfo(String userCode) throws Exception {
		try{
			System.out.println("**************************");
	//	String mil=String.valueOf(System.currentTimeMillis());
		//String sHttpPost = "http://10.112.5.133:7080/httpservice";
			String sHttpPost = "http://10.112.5.133:7080/httpservice";
		IMsgObject reqMo = new MsgObject(IMsgObject.MOType.initSR);
		String SourceSysID = "06002";              //请求方(发布方) 系统号    OA  
		String ServiceID = "06003000000008"; //响应方(发布方) 服务号    HR
		//获取系统时间
		Date date = new Date();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		String format = simpleDateFormat.format(date);
		reqMo.setSourceSysID(SourceSysID); //设置报文 请求方系统号      
		reqMo.setServiceID(ServiceID);     //设置报文 提供方服务号
		//reqMo.setSerialNO(format.substring(0, 8)+SourceSysID+System.currentTimeMillis());//设置报文流水号,第三段表示今天发送的第几的一次报文
		//reqMo.setServiceDateTime(format);  //设置报文 日期时间
		
		reqMo.setSerialNO("22222");//设置报文流水号,第三段表示今天发送的第几的一次报文
		reqMo.setServiceDateTime("1111");  //设置报文 日期时间
		//reqMo.setReqValue("string", userCode);
		reqMo.setReqValue("string", "084655");
		IMsgObject respMo = null;
		System.out.println("~~~~~~~~~~~~~~~~~1");
		log.info("reqMo:" + reqMo.toString());
		//直接访问WSDL调用方法

		MYWSServiceRequester mt = new MYWSServiceRequester(sHttpPost);
		log.info("reqMo1:" +mt );
		System.out.println("~~~~~~~~~~~~~~~~~2");
		respMo = mt.execute(reqMo);	
		List<GroupRecord> record2 = respMo.getResGroupRecord("return") ;
		JSONObject jo=new JSONObject();
		for (GroupRecord groupRecord : record2) {
			if(groupRecord.getFieldValue("psncode")==null){
			}else{
			PersonInfoByCodeBean pbc=new PersonInfoByCodeBean();
			//pbc.setJobNum(groupRecord.getFieldValue("psncode"));userCode
			System.out.println("~~~~~~~~~~~~~~~~~"+groupRecord.getFieldValue("psnname"));
			pbc.setJobNum(userCode);
			pbc.setName(groupRecord.getFieldValue("psnname"));
			pbc.setJob(groupRecord.getFieldValue("jobname"));
			System.out.println(pbc.getID());
			jo.put(pbc.getID(), pbc.getJSONObject());
		}	
// 		list 转jsonboject
 		return jo;}
		}catch(Exception e){
			log.error("******************************AAAAAAAAAAAAAAAAAAAAAAAAAAAAAa", e);
		}
		return null;

	}                                                                                         
public void setCodes(String codes) {
	this.codes = codes;
}
	
}







